/* app/actions/list.js */

import request from '../utils/request';

import { GET_GROUP_LIST,GET_USER_COLLECT,GET_TOPIC_RULE } from '../constants/actionTypes';


export function getUserCollect(params,onSuccess = (()=>{}),onError = (()=>{})) {
    var url = 'http://jsapi.tuan.ymatou.com/api/Topic/GetTopic';
    return {
        type: GET_USER_COLLECT,
        payload: {
            promise: request(url,{},params),
            onSuccess: onSuccess,
            onError: onError
        }
    }
}

export function getTopicRule(params,onSuccess = (()=>{}),onError = (()=>{})) {
    var url = 'http://jsapi.tuan.ymatou.com/api/Topic/GetRuleDescription';
    return {
        type: GET_TOPIC_RULE,
        payload: {
            promise: request(url,{},params),
            onSuccess: onSuccess,
            onError: onError
        }
    }
}

export function getCurrentGroupList(params,onSuccess = (()=>{}),onError = (()=>{})) {
    return showList(0,params);
}

export function getLatestGroupList(params,onSuccess = (()=>{}),onError = (()=>{})) {
   return showList(1,params,onSuccess,onError);
}

function showList(type,params,onSuccess = (()=>{}),onError = (()=>{})) {
    var url = `http://jsapi.tuan.ymatou.com/api/Tuan/GetGroupTuanList?Type=${type}`;
    return {
        type: GET_GROUP_LIST+'_'+(type?'LATEST':'CURRENT'),
        payload: {
            promise: request(url,{},params),
            onSuccess,
            onError
        }
    }
}